#!/bin/bash
#
# Sets initial Pulley subscription settings
#
# Author:   Dr. Mike Murphy (mmurphy2@coastal.edu)
# Revision: 19 November 2013
#
#   Copyright 2011-2013 Coastal Carolina University
#   Copyright 2007-2008 Clemson University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
# This material is based upon work supported under a National Science
# Foundation Graduate Research Fellowship. Any opinions, findings,
# conclusions or recommendations expressed in this publication are those of
# the author(s) and do not necessarily reflect the views of the National
# Science Foundation.
#


## p_cmd_bootstrap_help
##
## Echoes help information for the bootstrap command. Returns 0.
##
function p_cmd_bootstrap_help() {
	cat << EOF
Usage: pulley bootstrap [options] [bootstrap URL]

Configures the initial Pulley subscription. Subscription settings can be
entered manually using the [options], or by means of a [bootstrap URL].

Options:

--nokey
  Do not import public key (overrides --pubkey and the PUB_KEY entry in a
  [bootstrap URL]). If a security provider using a public key is specified,
  and this option is given, then the system administrator will need to
  import the key manually.

--pub-key <url>
  Import public key from <url>. This option corresponds to the PUB_KEY entry
  in a [bootstrap URL] file and specifies the URL or local file path to a
  public key to import. The key will be imported as part of the bootstrap
  process, unless --nokey is given.

--security <provider>
  Security <provider> to be used with the subscription (default: gpg). This
  option corresponds to the SECURITY entry in a [bootstrap URL] file.

--subscribe <url>
  Subscription <url> -- this URL is the URL of the "main" subscription file,
  which will vary by subscription type (mechanism). For some subscription
  types, this URL will be the same as the [bootstrap URL]; however, other
  subscription mechanisms may use other URL schemes. Whether this option is
  given, or the corresponding SUBSCRIBE entry in the [bootstrap URL] file
  is specified, this URL must be set in order for Pulley to work correctly.

--type <mechanism>
  Sets the subscription type to <mechanism>. This option corresponds to the
  TYPE entry in the [bootstrap URL] file. If not set, the subscription
  system defaults to using the twofile mechanism.

EOF
	return 0
}


## p_cmd_bootstrap_summary
##
## Echoes summary information for the bootstrap command. Returns 0.
##
function p_cmd_bootstrap_summary() {
	echo "Configures initial subscription"
	return 0
}


## p_cmd_bootstrap [options] <subscription url>
##
## Performs an initial bootstrap of the Pulley subscription, downloading the
## control file and importing the public key. Also optionally updates the
## subscription.
##
## [options] are defined in the core/subscription.module psub_bootstrap
## function.
##
## <subscription url> is the URL of the bootstrap file on the server
##
## Returns 0 on success, non-zero on failure
##
function p_cmd_bootstrap {
	psub_bootstrap "$@"
	return $?
}
